package com.hopu.mybatis.dao;

import com.hopu.mybatis.entity.TbBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Book表持久层接口
 */
public interface BookMapper {

    /**
     * 添加书籍
     * @param book
     */
//    @Insert({"insert into tb_book(book_name, book_price, book_author, book_publish_date, book_image)" +
//            " values(#{bookName},#{bookPrice},#{bookAuthor},#{bookPublishDate},#{bookImage})"})
    void add(TbBook book);

    void update(TbBook book);

    void delete(Long bookId);

//    @Results(id = "bookMap",value = {@Result(id = true,property = "bookId",column = "book_id"),
//            @Result(property = "bookName",column = "book_name"),
//            @Result(property = "bookAuthor",column = "book_author"),
//            @Result(property = "bookPrice",column = "book_price"),
//            @Result(property = "bookPublishDate",column = "book_publish_date"),
//            @Result(property = "bookImage",column = "book_image")})
//    @Select("select * from tb_book where book_id = #{bookId}")
    TbBook selectById( Long bookId);

//    @ResultMap(value = "bookMap")
//    @Select("select * from tb_book")
    List<TbBook> selectAll();

    /**
     * 按书籍的多个条件进行查询
     * @param book
     * @return
     */
    List<TbBook> selectByBook(TbBook book);

    /**
     * 按多个作者来查询书籍
     */
    List<TbBook> selectByAuthorNames(@Param("authorNames") List<String> authorNames);
}
